package com.edu.controller;
import com.edu.entity.User;
import com.edu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;
/*** @ProjectName: springboot-project28
 * @Titile: UserController
 * @Author: Administrator
 * @Description: 用户控制层
 */
@Controller //控制器注解
@RequestMapping("/user") //向外暴露的访问路径，这是一级
public class UserController {
  @Autowired
  private UserService userService;
  @RequestMapping("list") //这里是二级路径，完整路径就是  /user/list
  public String getAll(Model model){
    //调用业务层获取用户数据
    List<User> userList = userService.getAll();
    //将用户数据装进model中，这样在页面就可以拿这个数据
    model.addAttribute("users", userList);
    return "list"; //list是一个视图名称
   }
}
